package com.lancoo.znbkxx.teacher.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.widget.BamTextView
import kotlinx.android.synthetic.main.aibk_adapter_item_analysis_of_study.view.*
import kotlinx.android.synthetic.main.aibk_adapter_item_knowledge_area_count_txt.view.*
import kotlinx.android.synthetic.main.aibk_adapter_item_knowledge_area_txt.view.*

class AibkKnowledgeAreaCountAdapter(
        val context: Context,
        val strParentKnowledgeTitle:String,
        val strParentKnowledgeCount:String
) : KBaseRecyclerAdapter() {

    var TvKnowledgeAreaParentTitle: TextView?=null
    var TvKnowledgeAreaCount:BamTextView?=null
    var TvAnalysisOfStudy:BamTextView?=null

    override fun getHolderView(parent: ViewGroup?, position: Int): View? {
        var view:View? = null
        if(position == 1){
            view = LayoutInflater.from(context)
                    .inflate(R.layout.aibk_adapter_item_knowledge_area_count_txt, parent, false)
        }else if(position in 16..27){
            view = LayoutInflater.from(context)
                    .inflate(R.layout.aibk_adapter_item_analysis_of_study, parent, false)
        }else{
            view = LayoutInflater.from(context)
                    .inflate(R.layout.aibk_adapter_item_knowledge_area_txt, parent, false)
        }
        return view
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {
        if(position == 0){
            TvKnowledgeAreaParentTitle = holder.convertView.TvTxt
            holder.convertView.TvTxt.text = strParentKnowledgeTitle
        }else if(position == 1){
            TvKnowledgeAreaCount = holder.convertView.TvKnowledgeAreaCount
            holder.convertView.TvKnowledgeAreaCount.text = strParentKnowledgeCount+"个"
            holder.convertView.TvKnowledgeAreaCount.setOnClickListener {
                clickListener!!.onClick()
            }
        }else if(position == 2){
            holder.convertView.TvTxt.text = "知"
        }else if(position == 3){
            holder.convertView.TvTxt.text = "识"
        }else if(position == 4){
            holder.convertView.TvTxt.text = "点"
        }else if(position == 5){
            holder.convertView.TvTxt.text = "及"
        }else if(position == 6){
            holder.convertView.TvTxt.text = "班"
        }else if(position == 7){
            holder.convertView.TvTxt.text = "级"
        }else if(position == 8){
            holder.convertView.TvTxt.text = "学"
        }else if(position == 9){
            holder.convertView.TvTxt.text = "生"
        }else if(position == 10){
            holder.convertView.TvTxt.text = "历"
        }else if(position == 11){
            holder.convertView.TvTxt.text = "次"
        }else if(position == 12){
            holder.convertView.TvTxt.text = "学"
        }else if(position == 13){
            holder.convertView.TvTxt.text = "习"
        }else if(position == 14){
            holder.convertView.TvTxt.text = "轨"
        }else if(position == 15){
            holder.convertView.TvTxt.text = "迹"
        }else if(position == 16){
            TvAnalysisOfStudy = holder.convertView.TvAnalysisOfStudy
            holder.convertView.TvAnalysisOfStudy.text = "("
            holder.convertView.TvAnalysisOfStudy.setOnClickListener {
                clickListener!!.onClickAnother()
            }
        }else if(position == 17){
            TvAnalysisOfStudy = holder.convertView.TvAnalysisOfStudy
            holder.convertView.TvAnalysisOfStudy.text = "查"
            holder.convertView.TvAnalysisOfStudy.setOnClickListener {
                clickListener!!.onClickAnother()
            }
        }else if(position == 18){
            TvAnalysisOfStudy = holder.convertView.TvAnalysisOfStudy
            holder.convertView.TvAnalysisOfStudy.text = "看"
            holder.convertView.TvAnalysisOfStudy.setOnClickListener {
                clickListener!!.onClickAnother()
            }
        }else if(position == 19){
            TvAnalysisOfStudy = holder.convertView.TvAnalysisOfStudy
            holder.convertView.TvAnalysisOfStudy.text = "班"
            holder.convertView.TvAnalysisOfStudy.setOnClickListener {
                clickListener!!.onClickAnother()
            }
        }else if(position == 20){
            TvAnalysisOfStudy = holder.convertView.TvAnalysisOfStudy
            holder.convertView.TvAnalysisOfStudy.text = "级"
            holder.convertView.TvAnalysisOfStudy.setOnClickListener {
                clickListener!!.onClickAnother()
            }
        }else if(position == 21){
            TvAnalysisOfStudy = holder.convertView.TvAnalysisOfStudy
            holder.convertView.TvAnalysisOfStudy.text = "学"
            holder.convertView.TvAnalysisOfStudy.setOnClickListener {
                clickListener!!.onClickAnother()
            }
        }else if(position == 22){
            TvAnalysisOfStudy = holder.convertView.TvAnalysisOfStudy
            holder.convertView.TvAnalysisOfStudy.text = "情"
            holder.convertView.TvAnalysisOfStudy.setOnClickListener {
                clickListener!!.onClickAnother()
            }
        }else if(position == 23){
            TvAnalysisOfStudy = holder.convertView.TvAnalysisOfStudy
            holder.convertView.TvAnalysisOfStudy.text = "分"
            holder.convertView.TvAnalysisOfStudy.setOnClickListener {
                clickListener!!.onClickAnother()
            }
        }else if(position == 24){
            TvAnalysisOfStudy = holder.convertView.TvAnalysisOfStudy
            holder.convertView.TvAnalysisOfStudy.text = "析"
            holder.convertView.TvAnalysisOfStudy.setOnClickListener {
                clickListener!!.onClickAnother()
            }
        }else if(position == 25){
            TvAnalysisOfStudy = holder.convertView.TvAnalysisOfStudy
            holder.convertView.TvAnalysisOfStudy.text = "报"
            holder.convertView.TvAnalysisOfStudy.setOnClickListener {
                clickListener!!.onClickAnother()
            }
        }else if(position == 26){
            TvAnalysisOfStudy = holder.convertView.TvAnalysisOfStudy
            holder.convertView.TvAnalysisOfStudy.text = "告"
            holder.convertView.TvAnalysisOfStudy.setOnClickListener {
                clickListener!!.onClickAnother()
            }
        }else if(position == 27){
            TvAnalysisOfStudy = holder.convertView.TvAnalysisOfStudy
            holder.convertView.TvAnalysisOfStudy.text = ")"
            holder.convertView.TvAnalysisOfStudy.setOnClickListener {
                clickListener!!.onClickAnother()
            }
        }else if(position == 28){
            holder.convertView.TvTxt.text = "数"
        }else if(position == 29){
            holder.convertView.TvTxt.text = "据"
        }else if(position == 30){
            holder.convertView.TvTxt.text = "分"
        }else if(position == 31){
            holder.convertView.TvTxt.text = "析"
        }else if(position == 32){
            holder.convertView.TvTxt.text = "得"
        }else if(position == 33){
            holder.convertView.TvTxt.text = "来"
        }else if(position == 34){
            holder.convertView.TvTxt.text = "。"
        }

    }

    override fun getItemCount(): Int {
        return 34
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    public fun changeKnowledgeAreaCount(knowledgeAreaParentTitle:String,knowledgeAreaCount:String){
        TvKnowledgeAreaParentTitle!!.text = knowledgeAreaParentTitle
        TvKnowledgeAreaCount!!.text = knowledgeAreaCount+"个"
    }


    private var clickListener: OnClickListener? = null

    /*
   * 设置点击事件
   * */
    interface OnClickListener {
        fun onClick()
        fun onClickAnother()
    }

    fun setClickListener(clickListener: OnClickListener?) {
        this.clickListener = clickListener
    }

}